using System;
using System.Collections.Generic;
using System.Text;

namespace MasterLab
{
    class regresion
    {
     
        double[] x;
        double[] y;
       
        double sumx = 0;
        double sumy = 0;
        double sumxcua=0;
        double sumycua=0;
        double sumxy=0;
        double lectura=0;

        public regresion()
        { ;}


        public regresion(double[] y, double[] x, double lec)
        {
            this.lectura = lec;
            this.x = x;
            this.y = y;
        }

   
        public double r()
        {
            
            this.sumxy = 0;
            this.sumx = 0;
            this.sumy = 0;
            this.sumxcua = 0;
            this.sumycua = 0;
            int n = x.Length;
            double[] y2 = { 0, 0, 0, 0, 0,0 };

            for (int i = 0; i < x.Length; i++)
            {
                y2[i] = Logaritmo(y[i]);
                sumxy += y2[i] * x[i];
                sumx += x[i];
                sumy += y2[i];
                sumxcua += Math.Pow(x[i], 2);
                sumycua += Math.Pow(y2[i], 2);
            }

            /*R=ROUND((NUMREG*SUMXY-SUMy*SUMx)/SQRT((NUMREG*SUMyy-(SUMy*SUMy))*(NUMREG*SUMxx-(SUMx*SUMx))),3)*/
            double r1 = (n * sumxy - sumy * sumx);
            double r2=((n*sumycua)-(sumy*sumy))* ((n * sumxcua)-(sumx*sumx));
            double r3 = Math.Sqrt(r2);
            double r = Math.Round((r1 / r3),4);
            

            return r;
        }


        public double b()
        {
            this.sumxy = 0;
            this.sumx = 0;
            this.sumy = 0;
            this.sumycua = 0;
            this.sumxcua = 0;
            int n = x.Length;
            double[] y2 = { 0, 0, 0, 0, 0,0 };

            for (int i = 0; i < x.Length; i++)
            {
               
                y2[i] = Logaritmo(y[i]);
                sumxy += y2[i] * x[i];
                sumx += x[i];
                sumy += y2[i];
                sumxcua += Math.Pow(x[i], 2);
                sumycua += Math.Pow(y2[i], 2);
              
            }

            /*B=ROUND((SUMx*SUMyy-SUMy*SUMXY)/(NUMREG*SUMyy-SUMy*SUMy),3)*(Formula de Laser)*/
            double b1 = (sumx * sumycua - sumy * sumxy);
            double b2 = (n * sumycua - sumy * sumy);
            double b = Math.Round((b1 / b2),4);
          
           
      

            return b;
        }

        public double m()
        {
            this.sumxy = 0;
            this.sumx = 0;
            this.sumy = 0;
            this.sumycua = 0;
            this.sumxcua = 0;
            int n = x.Length;
            double[] y2 ={0,0,0,0,0,0};

            for (int i = 0; i < x.Length; i++)
            {
               
                y2[i] = Logaritmo(y[i]);
                sumxy += y2[i] * x[i];
                sumx += x[i];
                sumy += y2[i];
                sumxcua += Math.Pow(x[i], 2);
                sumycua += Math.Pow(y2[i], 2);
                
            }
   
            /* M=ROUND((NUMREG*SUMXY-SUMy*SUMx)/(NUMREG*SUMyy-SUMy*SUMy),3)*(Formula de Laser)*/
            double m1 = ((n * sumxy) - (sumy * sumx));
            double m2 = ((n * sumycua) - (sumy * sumy));
            double m = Math.Round((m1 / m2),4);

     

            return m;
        }

        public double z()
        {
            
            /*z=ROUND(m*abs+b,2)*/
            double b1 = b();
            double m1 = m();
            double z = Math.Round(((m1*lectura) + b1),2);

             return z;
        }

        public double Logaritmo(double var)
        {
            if (var != 0)
            {
                return 2 - Math.Log10(var);
            }
            else 
            {
                return 0;
            }
        }
        
      /*  public static void Main(String[] args)
        {

            
            //double[] x = { 94, 88,81, 75, };
            //double[] y = { 0.25, 0.50, 0.75, 1.0 };

            //double[] x = { 100, 94, 88, 81, 75 };
            //double[] y = { 0, 0.25, 0.50, 0.75, 1.0 };

            regresion obj = new regresion();
            double l = obj.lectura;

            double transf = Logaritmo(l);
            

            regresion re = new regresion(x, y,transf );
            
            
            /*double b2 = re.b();
            double r2 = re.r();
            double m2 = re.m();
            double z2 = re.z();

            Console.WriteLine("R : " + r2);
            Console.WriteLine("B : " + b2);
            Console.WriteLine("M : "+m2);

            Console.WriteLine("Z : " + z2);
           
            

        }*/
    }
}
